from django.db import models
from django.utils.regex_helper import Choice
from hwcorp.apps.constants import *
from django.template.defaultfilters import default
from django.contrib.auth.models import User

# Create your models here.
class Tag(models.Model):
    count = models.IntegerField("Count", default = 0)
    name = models.CharField("Tag name", max_length = 255)
    icon = models.ImageField("Icon", blank = True, upload_to = "/media/img/tag_icon/")
    description = models.CharField("Description", blank = True, max_length = 255)
    def __unicode__(self):
        return str(self.name)
     
class Blog(models.Model):
    owner = models.ForeignKey(User)
    title = models.CharField("Title of the Blog", max_length = 100)
    tagline = models.CharField("Tag line", max_length = 200, blank = True)
    slug = models.SlugField(max_length = 100, unique = True, db_index = True, blank = True)
    posts_per_page = models.IntegerField("Posts per page", default = 10)

    template = models.CharField("Template path", max_length = 100, blank = True)
    description = models.CharField(blank = True, max_length = 255)
    def __unicode__(self):
        return str(self.title)
class Post(models.Model):
    title = models.CharField("Post Title", max_length = 100)
    slug = models.SlugField("Post Slug", max_length = 100, db_index = True)
    privacy_level = models.CharField('Privacy level', max_length = 255, choices = PRIVACY_LEVELS)

    allow_comments = models.BooleanField("Allow Comments?", default = True)
    show_comments = models.BooleanField("Show Comments?", default = True)

    series = models.CharField("Series name", max_length = 100, blank = True, default = "")
    source = models.CharField("Post source", max_length = 100, blank = True, default = "")

    created_time = models.DateTimeField(auto_now_add = True)
    edit_time = models.DateTimeField(auto_now = True)
    

    tags = models.ManyToManyField(Tag, blank = True)

    content = models.TextField("Content", max_length = 2000)


    blog = models.ForeignKey(Blog)
    view = models.IntegerField("Views", default = 0)
    
    def __unicode__(self):
        return str(self.title)
    def increase_view(self):
        self.view += 1
    
class Comment(models.Model):
    post = models.ForeignKey(Post)
    content = models.TextField("Content", max_length = 2000)
    date = models.DateTimeField("Date created", auto_now_add = True)
    
    owner = models.ForeignKey(User, blank = True, null = True, default = None)
    
    title = models.CharField("Title", blank = True, max_length = 255)
    name = models.CharField("Author's name", max_length = 100)
    email = models.EmailField("Author's email", blank = True)

    visible = models.BooleanField(default = False)

    def __unicode__(self):
        return str(self.post) + " " + str(self.title)
     

    
